/* eslint-disable camelcase */
/*
 * @Description:
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-07-04 07:27:10
 * @LastEditors: swc shanwenchao12138@163.com
 * @LastEditTime: 2025-03-11 14:22:06
 */
import { ifs, ts, Tsrv } from '@/services';

import { N_oMagicbox, N_oSimpleToolbar } from '@/types';
import { N_cpms } from '../types';
import { T_pmsBase } from './base';

class T_cmd extends T_pmsBase {
  // 外观权限旧值
  private oldActDataMap: Map<string, boolean> = new Map();

  // 外观权限数据地图
  private actDataMap: Map<string, any> = new Map();

  // 角色功能旧值 key = 功能组ID
  private oldRoleFunMap: Map<string, N_cpms.I_roleFunItem> = new Map();

  private roleFunMap: Map<string, N_cpms.I_roleFunItem> = new Map();

  // 外观权限按扭
  private actToolbarMap: Map<string, N_oSimpleToolbar.I_Conf> = new Map();

  // 角色功能按扭
  private roleFunsToolbarMap: Map<string, N_oSimpleToolbar.I_Conf> = new Map();

  private loading = {
    loadFun: false,
    loadAction: false
  };

  // 主组件created里初始化
  public init(self: any, compBoxInfo: ifs.I_compBoxInfo) {
    this.self = self;
    this.compBox = compBoxInfo.TcompBox;
    this.compID = compBoxInfo.compID;
    self.actToolbarList.forEach(el => {
      this.actToolbarMap.set(el.key, el);
    });
    self.funToolbarList.forEach(el => {
      this.roleFunsToolbarMap.set(el.key, el);
    });
  }

  public clearActData() {
    this.self.fieldList = [];
    this.self.otherList = [];
    this.self.baseList = [];
    this.oldActDataMap.clear();
    this.actDataMap.clear();
  }

  /**
   * @description: 加载角色功权限
   * @param {string} roleFunID 角色功能ID
   * @return {void}
   * @author: wiz
   * @Date: 2023-07-06 10:32:19
   * @LastEditors: wiz
   * @LastEditTime: Do not edit
   */
  public loadActionData(roleFunsID: string) {
    if (this.loading.loadAction) {
      return;
    }
    this.loading.loadAction = true;
    this.clearActData();
    if (Tsrv.utils.noValue(roleFunsID)) {
      return;
    }

    const gpd = new ts.T_getPartDataArg();
    gpd.setLang(this.self.$i18n.locale ?? 'en-US').setDbType('mysql');
    gpd.setFunName(Tsrv.globalVar.funName.PMS_ACT).setRule({} as ifs.I_rule);
    gpd.setPage(1, 999999);
    gpd.setFilter({
      _sys_roleobj_funs_id: { $eq: roleFunsID }
    });
    Tsrv.getData<any, ifs.I_getPartDataArg>(gpd)
      .then(([b, res, rows, m]) => {
        if (!(b && res.data.total > 0)) {
          this.self.$srv.getI18nByPath(m ?? res.msg);
          return;
        }
        this.currRoleFunsID = roleFunsID;
        rows.forEach(el => {
          const title: string = el[Tsrv.globalVar.fieldName.m2oAspEleIdTitle];
          const val: boolean = el['f_enabled'] === 1;
          if (title && el.area !== 'default') {
            this.actDefaultHandle(title, val, el);
          } else {
            this.actOtherHandle(title, val, el);
          }
        });
        if (this.oldActDataMap.size > 0) {
          this.setActToolbar('openData');
        }
        this.loading.loadAction = false;
      })
      .catch(r => {
        throw new Error(r);
      });
  }

  public setActToolbar(
    modal: 'openData' | 'dataChanged' | 'dataNoChange' | 'disabledAll' | 'saved'
  ) {
    if (modal === 'openData') {
      this.actToolbarMap.get('selectAll').disabled = false;
      this.actToolbarMap.get('unSelectAll').disabled = false;
      this.actToolbarMap.get('cpFromRole').disabled = false;
      this.actToolbarMap.get('refresh').disabled = false;
    } else if (modal === 'disabledAll') {
      this.setActToolbarSetAll(true);
    } else if (modal === 'dataChanged') {
      this.actToolbarMap.get('save').disabled = false;
    } else if (modal === 'dataNoChange') {
      this.actToolbarMap.get('save').disabled = true;
    } else if (modal === 'saved') {
      this.actToolbarMap.get('save').disabled = true;
    }
  }

  private setActToolbarSetAll(p: boolean) {
    this.actToolbarMap.forEach(v => {
      v.disabled = p;
    });
  }

  private actOtherHandle(title: string, val: boolean, el: any) {
    let browseVal: boolean = false;
    if (title === 'browse') {
      browseVal = val;
    }
    this.self.baseList.push({
      name: title,
      title,
      val,
      disabled: false,
      actID: el.id
    } as N_cpms.I_actItem);
    this.oldActDataMap.set(title, val);
    this.actDataMap.set(title, el);
    this.browseSwitchVal = browseVal;
  }

  private actDefaultHandle(title: string, val: boolean, el: any) {
    if (el.area === 'table' || el.area === 'form') {
      this.self.fieldList.push({
        name: title,
        title,
        val,
        disabled: false,
        actID: el.id
      } as N_cpms.I_actItem);
      this.oldActDataMap.set(title, val);
      this.actDataMap.set(title, el);
    } else {
      this.self.otherList.push({
        name: title,
        title,
        val,
        disabled: false,
        actID: el.id
      } as N_cpms.I_actItem);
      this.oldActDataMap.set(title, val);
      this.actDataMap.set(title, el);
    }
  }

  public clearFunsData() {
    this.self.roleFunList = [];
    this.oldRoleFunMap.clear();
    this.roleFunMap.clear();
  }

  /**
   * @description: 角色功能
   * @param {string} roleID
   * @return {*}
   * @author: wiz
   * @Date: 2023-07-09 11:09:46
   * @LastEditors: clr
   * @LastEditTime: Do not edit
   */
  public loadFunData(roleID: string, isBeginLoad: boolean = true) {
    if (this.loading.loadFun) {
      return;
    }
    this.loading.loadFun = true;
    const that = this;
    this.clearFunsData();
    that.clearActData();
    if (Tsrv.utils.noValue(roleID)) {
      return;
    }

    const gpd = new ts.T_getPartDataArg();
    let ruleEventMsg: N_cpms.I_ruleEventMsg = null;
    gpd
      .setLang(this.self.$i18n.locale ?? Tsrv.globalVar.i18n.enUS)
      .setDbType(Tsrv.globalVar.dbType.MYSQL);
    gpd.setFunName(Tsrv.globalVar.funName.PMS_FUN).setRule({} as ifs.I_rule);
    gpd.setPage(1, 9999);
    gpd.setFilter({
      [Tsrv.globalVar.fieldName.pmsRoleID]: { $eq: roleID }
    });
    Tsrv.getData<any, ifs.I_getPartDataArg>(gpd)
      .then(([b, res, rows, m]) => {
        if (!(b && res.data.total > 0)) {
          that.self.$srv.getI18nByPath(m ?? res.msg);
          return;
        }
        that.roleFunsDataHandle(rows);
        let i: number = 0;
        let roleFunID: string = '';
        that.roleFunMap.forEach((val, key) => {
          this.oldRoleFunMap.set(key, Tsrv.utils.cloneNoMatchVue(val, true));
          if (i === 0) {
            this.self.openFunList.push(val.groupID);
            if (val.funs.length > 0) {
              // 默认选择cell
              val.funs[0].cellClick = true;
              this.displayFunGroup(
                val.funs[0][Tsrv.globalVar.fieldName.m2oFunTitle],
                val.groupID
              );
              this.currFunID = val.funs[0][Tsrv.globalVar.fieldName.funID];
              roleFunID = val.funs[0].id;
              if (isBeginLoad) {
                ruleEventMsg = this.getRuleEventMsg(roleFunID, val.funs[0]);
              }
            }
          }
          i++;
          that.self.roleFunList.push(val);
        });
        if (Tsrv.utils.noValue(roleFunID)) {
          return;
        }
        that.currRoleFunsID = roleFunID;
        this.setRoleFunsToolbar('openData');
        this.loadActionData(roleFunID);
        if (ruleEventMsg !== null) {
          this.self.loadRoleRule(ruleEventMsg);
        }
        this.loading.loadFun = false;
      })
      .catch(r => {
        throw new Error(r);
      });
  }

  // 显示主副功能
  public async displayFunGroup(funName: string, funGroupID: string) {
    const [b, res, rows, msg] = await this.doQueryFun(funName, funGroupID);
    if (!b) {
      this.self.$msg(res.msg);
    } else {
      if (res.data.total === 1 && rows[0]['parent_fun_name'] !== '') {
        const [b1, res1, rows1, msg1] = await this.doQueryFun(
          rows[0].parent_fun_name,
          funGroupID
        );
        if (res1.data.total !== 0) {
          const titles = [];
          rows1.forEach(el => {
            titles.push(el.title);
          });
          this.gBackGroup(funGroupID, titles);
        }
      } else {
        if (res.data.total !== 0) {
          const titles = [];
          rows.forEach(el => {
            titles.push(el.title);
          });
          this.gBackGroup(funGroupID, titles);
        }
      }
    }
  }

  private doQueryFun(funName: string, funGroupID: string) {
    const gpfd = new ts.T_GPFD();
    gpfd
      .setDbType(Tsrv.globalVar.dbType.MYSQL)
      .setFunName(Tsrv.globalVar.funName.FUN)
      .setLang(this.self.$i18n.locale || 'en_US');
    gpfd.setAgreedFields('title', 'parent_fun_name');
    gpfd.setFilter({
      $or: [{ title: { $eq: funName } }, { parent_fun_name: { $eq: funName } }]
    });
    return Tsrv.getData<{ title: string; parent_fun_name: string }, ifs.I_GPFD>(
      gpfd
    );
  }

  public setRoleFunsToolbar(
    modal: 'openData' | 'dataChange' | 'dataNoChange' | 'isSelect' | 'noSelect'
  ) {
    if (modal === 'openData') {
      this.roleFunsToolbarMap.get('cpFromRole').disabled = false;
      this.roleFunsToolbarMap.get('refresh').disabled = false;
      this.roleFunsToolbarMap.get('delete').disabled = true;
      this.roleFunsToolbarMap.get('save').disabled = true;
    } else if (modal === 'dataChange') {
      this.roleFunsToolbarMap.get('save').disabled = false;
    } else if (modal === 'dataNoChange') {
      this.roleFunsToolbarMap.get('save').disabled = true;
    } else if (modal === 'isSelect') {
      this.roleFunsToolbarMap.get('delete').disabled = false;
    } else if (modal === 'noSelect') {
      this.roleFunsToolbarMap.get('delete').disabled = true;
    }
  }

  private roleFunsDataHandle(rows: Array<any>) {
    for (const obj of rows) {
      // 增加两个属性
      obj['chkBoxDisabled'] = true;
      obj['chkVal'] = false;
      obj['cellClick'] = false;
      obj['deleted'] = false;
      obj['hintTitle'] = false;
      obj['background'] = false;
      const gID: string = obj[Tsrv.globalVar.fieldName.funGroupID];
      if (this.roleFunMap.has(gID)) {
        const mItm: N_cpms.I_roleFunItem = this.roleFunMap.get(gID);
        if (mItm.roleFunIDS.has(obj.id)) {
          continue;
        } else {
          mItm.roleFunIDS.add(obj.id);
          mItm.funs.push(obj);
          mItm.funsInfo.currCount++;
        }
      } else {
        this.roleFunMap.set(gID, {
          selStatus: 'closeSel',
          groupTitle: obj[Tsrv.globalVar.fieldName.m2oFunGroupTitle],
          groupID: obj[Tsrv.globalVar.fieldName.funGroupID],
          roleFunIDS: new Set<string>([obj.id]),
          funsInfo: {
            count: 0, // 总笔数
            currCount: 1, // 当前笔数
            deleteCount: 0 // 删除笔数
          },
          funs: [obj]
        } as N_cpms.I_roleFunItem);
      }
    }
  }

  public diffActData(
    baseList: Array<any> = null,
    fieldList: Array<any> = null,
    otherList: Array<any> = null
  ): boolean {
    let isChange: boolean = false;
    if (!Tsrv.utils.noValue(baseList)) {
      let ok: boolean = false;
      for (const baseNewV of baseList) {
        if (this.oldActDataMap.get(baseNewV.name) !== baseNewV.val) {
          ok = true;
          break;
        }
      }
      if (ok) {
        isChange = ok;
      }
    }
    if (isChange) {
      return isChange;
    }
    if (!Tsrv.utils.noValue(fieldList)) {
      let ok: boolean = false;
      for (const fieldNewV of fieldList) {
        if (this.oldActDataMap.get(fieldNewV.name) !== fieldNewV.val) {
          ok = true;
          break;
        }
      }
      if (ok) {
        isChange = ok;
      }
    }
    if (isChange) {
      return isChange;
    }
    if (!Tsrv.utils.noValue(otherList)) {
      let ok: boolean = false;
      for (const otherNewV of otherList) {
        if (this.oldActDataMap.get(otherNewV.name) !== otherNewV.val) {
          ok = true;
          break;
        }
      }
      if (ok) {
        isChange = ok;
      }
    }
    return isChange;
  }

  private getCtdData(): Array<ifs.I_ctdUpdData> {
    function getData(d: N_cpms.I_actItem): ifs.I_ctdUpdData {
      const udata = new ts.T_ctdUpdData();
      udata.setDataRule({} as ifs.I_rule).setFileInfo({});
      udata.setFilter({ id: { $eq: d.actID } });
      udata.setRowData({
        field: 'f_enabled',
        value: d.val ? 1 : 0
      } as ifs.I_fv);
      return udata;
    }
    const updDatas: Array<ifs.I_ctdUpdData> = [];
    for (const baseD of this.self.baseList) {
      if (this.oldActDataMap.has(baseD.name)) {
        if (this.oldActDataMap.get(baseD.name) === baseD.val) {
          continue;
        }
      } else {
        throw new Error('无旧数据');
      }
      updDatas.push(getData(baseD));
    }
    for (const fieldD of this.self.fieldList) {
      if (this.oldActDataMap.has(fieldD.name)) {
        if (this.oldActDataMap.get(fieldD.name) === fieldD.val) {
          continue;
        }
      } else {
        throw new Error('无旧数据');
      }
      updDatas.push(getData(fieldD));
    }
    for (const otherD of this.self.otherList) {
      if (this.oldActDataMap.has(otherD.name)) {
        if (this.oldActDataMap.get(otherD.name) === otherD.val) {
          continue;
        }
      } else {
        throw new Error('无旧数据');
      }
      updDatas.push(getData(otherD));
    }
    return updDatas;
  }

  public doActSave() {
    if (Tsrv.utils.noValue(this.currRoleFunsID)) {
      return;
    }
    const ctdData = this.getCtdData();

    const ctd = new ts.T_ctdUpdRec();

    ctd.setCtdUpdDatas(...ctdData);
    Tsrv.updRows(
      Tsrv.lexicon.globalVar.tableName.PMS_ACT,
      Tsrv.lexicon.globalVar.dbType.MYSQL,
      {} as ifs.I_rule,
      ctd
    )
      .then(([b, res, msg]) => {
        this.self.$msg(msg ?? res.msg);
        if (b) {
          this.loadActionData(this.currRoleFunsID);
          this.setActToolbar('saved');
        }
      })
      .catch(r => {
        throw new Error(r);
      });
  }

  public roleFunRadioClick(groupID: string, label: string) {
    if (this.roleFunMap.has(groupID)) {
      const val = this.roleFunMap.get(groupID);
      switch (label) {
        case 'closeSel':
          val.funs.forEach(el => {
            el.chkBoxDisabled = true;
          });
          break;
        case 'multipleChoice':
          val.funs.forEach(el => {
            el.chkBoxDisabled = false;
          });
          break;
        case 'selectAll':
          val.funs.forEach(el => {
            el.chkVal = true;
            el.chkBoxDisabled = false;
          });
          this.selectChange();
          break;
        case 'notAll':
          val.funs.forEach(el => {
            el.chkVal = false;
          });
          this.selectChange();
          break;
        default:
          throw new Error('不能识别的类型');
      }
    }
  }

  public selectChange(p?: boolean) {
    for (const [k, v] of this.roleFunMap) {
      for (const val of v.funs) {
        if (val.chkVal) {
          this.setRoleFunsToolbar('isSelect');
          return;
        }
      }
    }
    this.setRoleFunsToolbar('noSelect');
  }

  public roleFunItemClick(groupID: string, roleFunID: string) {
    if (this.roleFunMap.has(groupID)) {
      this.roleFunMap.forEach(el => {
        el.funs.forEach(fn => {
          fn.cellClick = false;
        });
      });
      const val = this.roleFunMap.get(groupID);
      this.setActToolbar('disabledAll');
      for (const v of val.funs) {
        if (v.id === roleFunID) {
          v.cellClick = true;
          this.loadActionData(v.id);
          this.displayFunGroup(
            v[Tsrv.globalVar.fieldName.m2oFunTitle],
            groupID
          );
          break;
        }
      }
    }
  }

  public hintTitle(groupID: string, v: string) {
    if (this.roleFunMap.has(groupID)) {
      const val = this.roleFunMap.get(groupID);

      val.funs.forEach((el, idx) => {
        const title = Tsrv.getI18nBySrv(
          el[Tsrv.globalVar.fieldName.m2oFunTitle]
        );
        const lV = v.toLowerCase();
        if (title.toLowerCase().includes(lV) && !Tsrv.utils.noValue(lV)) {
          val.funs[idx].hintTitle = true;
        } else {
          val.funs[idx].hintTitle = false;
        }
      });
    }
  }

  public gBackGroup(groupID: string, v: string[]) {
    if (this.roleFunMap.has(groupID)) {
      const val = this.roleFunMap.get(groupID);
      val.funs.forEach((el, idx) => {
        const title = el[Tsrv.globalVar.fieldName.m2oFunTitle];
        if (v.indexOf(title) > -1) {
          val.funs[idx].background = true;
        } else {
          val.funs[idx].background = false;
        }
      });
    }
  }

  public actCpFromRole(cf: N_oSimpleToolbar.I_Conf, e: any) {
    this.openWindow(
      Tsrv.globalVar.funName.PMS_ROLE,
      cf,
      this.getMagicBoxConf(e)
    )
      .then(d => {
        if (d?.data && Array.isArray(d.data)) {
          if (d.data.length > 1) {
            this.self.$msg(Tsrv.getI18nByValue('只能选择一项'));
            return;
          }
          // 找到并赋值
          const roleID: string = d.data[0]?.id;
          if (!Tsrv.utils.noValue(roleID)) {
            this.cpActByRole(roleID).then(b => {
              if (b) {
                this.loadActionData(this.currRoleFunsID);
              }
            });
          }
        }
      })
      .catch(r => {
        throw new Error(r);
      });
  }

  private cpActByRole(roleID: string): Promise<boolean | unknown> {
    return new Promise(resolve => {
      const p = {
        dbType: Tsrv.globalVar.dbType.MYSQL,
        lang: this.self.$i18n.locale,
        cmd: 'cpAct',
        fromRoleID: roleID,
        toRoleID: this.currRoleID,
        toRoleFunsID: this.currRoleFunsID,
        funID: this.currFunID,
        accSetID: this.accSetID
      };
      Tsrv.standardPostReq<any, any>(p, Tsrv.lexicon.url.pmsHandle).then(
        ([res, msg]) => {
          resolve(true);
        }
      );
    }).catch(err => {
      throw new Error(err);
    });
  }

  public funCpFromRole(cf: N_oSimpleToolbar.I_Conf, e: any) {
    this.openWindow(
      Tsrv.globalVar.funName.PMS_ROLE,
      cf,
      this.getMagicBoxConf(e)
    )
      .then(d => {
        if (d?.data && Array.isArray(d.data)) {
          if (d.data.length > 1) {
            this.self.$msg(Tsrv.getI18nByValue('只能选择一项'));
            return;
          }

          // 找到并赋值
          const roleID: string = d.data[0]?.id;
          if (!Tsrv.utils.noValue(roleID)) {
            this.cpFunByRole(roleID).then(b => {
              if (b) {
                this.loadFunData(this.currRoleID);
              }
            });
          }
        }
      })
      .catch(r => {
        throw new Error(r);
      });
  }

  private cpFunByRole(roleID: string): Promise<boolean | unknown> {
    return new Promise(resolve => {
      const p = {
        dbType: Tsrv.globalVar.dbType.MYSQL,
        lang: this.self.$i18n.locale,
        cmd: 'cpAllFun',
        fromRoleID: roleID,
        toRoleID: this.currRoleID,
        accSetID: this.accSetID
      };
      Tsrv.standardPostReq<any, any>(p, Tsrv.lexicon.url.pmsHandle).then(
        ([res, msg]) => {
          resolve(true);
        }
      );
      resolve(true);
    }).catch(err => {
      throw new Error(err);
    });
  }

  public funCpFromRoleByFunGroup(item: N_cpms.I_roleFunItem, e: any) {
    this.openWindow(
      Tsrv.globalVar.funName.PMS_ROLE,
      item,
      this.getMagicBoxConf(e)
    )
      .then(d => {
        if (d?.data && Array.isArray(d.data)) {
          if (d.data.length > 1) {
            this.self.$msg(Tsrv.getI18nByValue('只能选择一项'));
            return;
          }

          // 找到并赋值
          const roleID: string = d.data[0]?.id;
          if (!Tsrv.utils.noValue(roleID)) {
            this.cpFunByFunGroup(roleID, item.groupID).then(b => {
              if (b) {
                this.loadFunData(this.currRoleID);
              }
            });
          }
        }
      })
      .catch(r => {
        throw new Error(r);
      });
  }

  private cpFunByFunGroup(
    roleID: string,
    groupID: string
  ): Promise<boolean | unknown> {
    return new Promise(resolve => {
      const p = {
        dbType: Tsrv.globalVar.dbType.MYSQL,
        lang: this.self.$i18n.locale,
        cmd: 'cpRoleByFunGroup',
        fromRoleID: roleID,
        toRoleID: this.currRoleID,
        accSetID: this.accSetID,
        funGroupID: groupID
      };
      Tsrv.standardPostReq<any, any>(p, Tsrv.lexicon.url.pmsHandle).then(
        ([res, msg]) => {
          resolve(true);
        }
      );
      resolve(true);
    }).catch(err => {
      throw new Error(err);
    });
  }

  public funItemCpFromRole(funName: string, filter: object, e) {
    const conf: N_oMagicbox.I_conf = {};
    this.openWindow(funName, e, conf);
  }

  public funAddByFunGroup(item: N_cpms.I_roleFunItem, e: any) {
    this.self.addFunData = [];
    this.getAddFunData('addFunByFunGroup', item.groupID);
  }

  private getAddFunData(s: 'addFun' | 'addFunByFunGroup', groupID?: string) {
    this.findCanUseFuns(s, groupID)
      .then(([res, msg]) => {
        msg && this.self.$msg(msg);
        if (Array.isArray(res?.data)) {
          res.data.forEach(el => {
            if (el?.title) {
              el.title = Tsrv.getI18nBySrv(el.title);
            }
            if (Array.isArray(el?.children)) {
              el.children.forEach(itm => {
                if (itm?.title) {
                  itm.title = Tsrv.getI18nBySrv(itm.title);
                }
              });
            }
          });
          this.self.addFunData = res.data;
        }
      })
      .catch(err => {
        throw new Error(err);
      });
  }

  public addFun() {
    this.self.addFunData = [];
    this.getAddFunData('addFun');
  }

  public deleteFun() {
    this.delFunsIDs = [];
    let isChange: boolean = false;
    this.roleFunMap.forEach((v, k) => {
      for (const fn of v.funs) {
        if (fn.chkVal) {
          fn.deleted = true;
          v.funsInfo.deleteCount++;
          isChange = true;
          this.delFunsIDs.push(fn.id);
        }
      }
    });

    if (isChange) {
      this.setRoleFunsToolbar('dataChange');
    }
  }

  public doFunsSave() {
    this.funsSave()
      .then(([r, m]) => {
        !m && this.self.$msg(m);
        this.self.$msg(r.msg);
        if (r.success) {
          this.loadFunData(this.currRoleID);
        }
      })
      .catch(err => {
        throw new Error(err);
      });
  }

  public actChange(s?: 'base' | 'field' | 'other' | 'auto') {
    const base = this.self.baseList;
    const field = this.self.fieldList;
    const other = this.self.otherList;
    const isChange: boolean = this.diffActData(
      s === 'base' ? base : s === 'auto' ? base : null,
      s === 'base'
        ? field
        : s === 'field'
        ? field
        : s === 'auto'
        ? field
        : null,
      s === 'base' ? other : s === 'other' ? other : s === 'auto' ? other : null
    );
    if (isChange) {
      this.setActToolbar('dataChanged');
    } else {
      this.setActToolbar('dataNoChange');
    }
  }

  public addSelectFun() {
    const that = this;
    that.addFunIDs = [];
    that.self.selectFuns.forEach(el => {
      that.addFunIDs.push(el.data[Tsrv.globalVar.fieldName.funID]);
    });
    this.doFunsSave();
  }

  public getRuleEventMsg(roleFunsID: string, data: any): N_cpms.I_ruleEventMsg {
    return {
      type: 'search',
      content: {
        ikey: 'id',
        ukey: Tsrv.globalVar.fieldName.roleobjFunsId,
        val: [roleFunsID]
      },
      listenType: 'default',
      option: {
        autoCompleteInfo: {
          key: roleFunsID,
          table: Tsrv.globalVar.funName.PMS_FUN,
          data
        }
      }
    };
  }

  public refreshCache() {
    Tsrv.doEvent('_sys_fun_conf_resresh', null, () => null).then(r => {
      if (r.isErr()) {
        this.self.$msg(r.errmsg);
      } else {
        this.self.$msg('50003,FE,90');
      }
    });
  }
}
export interface I_cmd extends T_cmd {}
export const Tcmd = new T_cmd();
